import {
    ElMessage
} from "element-plus";
import {
    refreshToken
} from '@/api/xpert'
import {
    refreshTokenKc
} from '@/api/knowClub/index.js'
// 刷新xptoken
export const refrestTokenXP = async () => {
    let obj = JSON.parse(localStorage.getItem("logininfo"));
    let tokenobj = await refreshToken({
        refreshToken: JSON.parse(localStorage.getItem("logininfo")).refreshTokenXp
    });
    if (tokenobj.code == 400) {
        // /跳转登录
        localeStorage.removeItem('xpToken')
        localeStorage.removeItem('kcToken')
        localeStorage.removeItem('logininfo')
        localeStorage.removeItem('userInfo')
        router.replace('/Login?act=xp')
        return
    }
    obj.refreshTokenXp = tokenobj.data.refreshTokenXp;
    obj.accessTokenXp = tokenobj.data.accessTokenXp;
    localStorage.setItem("logininfo", JSON.stringify(obj));
    localStorage.setItem("xpToken", tokenobj.data.accessTokenXp);
}
// 刷新kctoken
export const refrestTokenKC = async () => {
    console.log("7777777777777777777777777777777777777777777");
    let obj = JSON.parse(localStorage.getItem("logininfo"));
    let tokenobj = await refreshTokenKc({
        refreshToken: JSON.parse(localStorage.getItem("logininfo")).refreshTokenKc
    });
    if (tokenobj.code == 400) {
        // /跳转登录
        localeStorage.removeItem('xpToken')
        localeStorage.removeItem('kcToken')
        localeStorage.removeItem('logininfo')
        localeStorage.removeItem('userInfo')
        router.replace('/Login?act=kc')
        return
    }
    obj.refreshTokenKc = tokenobj.data.refreshTokenKc;
    obj.accessTokenKc = tokenobj.data.accessTokenKc;
    localStorage.setItem("logininfo", JSON.stringify(obj));
    localStorage.setItem("kcToken", tokenobj.data.accessTokenKc);
}
// export const baseUrl = 'http://172.16.1.68:40080'
export const baseUrl = 'http://www.xpertbay.com'
export const timelist = [{
    value: '30',
    label: '30mins'
}, {
    value: '60',
    label: '60mins'
}, {
    value: '90',
    label: '90mins'
}, {
    value: '120',
    label: '120mins'
}]

export const datalist = [{
    value: '6',
    label: 'At least 6 hour'
}, {
    value: '24',
    label: 'At least 1 day'
}, {
    value: '48',
    label: 'At least 2 days'
}, {
    value: '72',
    label: 'At least 3 days'
}, {
    value: '96',
    label: 'At least 4 days'
}, {
    value: '120',
    label: 'At least 5 days'
}, {
    value: '144',
    label: 'At least 6 days'
}, {
    value: '168',
    label: 'At least 7 days'
}, {
    value: '192',
    label: 'At least 8 days'
}, {
    value: '216',
    label: 'At least 9 days'
}]
export const weeklist = [{
    value: '1',
    label: '1 weeks in advance'
}, {
    value: '2',
    label: '2 weeks in advance'
}, {
    value: '3',
    label: '3 weeks in advance'
}, {
    value: '4',
    label: '4 weeks in advance'
}, {
    value: '5',
    label: '5 weeks in advance'
}, {
    value: '6',
    label: '6 weeks in advance'
}, {
    value: '7',
    label: '7 weeks in advance'
}, {
    value: '8',
    label: '8 weeks in advance'
}, {
    value: '9',
    label: '9 weeks in advance'
}, {
    value: '10',
    label: '10 weeks in advance'
}]



export const getTime = (timestamp) => {
    if (!timestamp) return '--'
    const now = +new Date();
    const diff = ((now - timestamp) / 1000);

    if (diff < 60) {
        if (diff < 1) {
            return `${Math.ceil(diff).toFixed(0)||1} seconds ago`
        }
        return `${diff.toFixed(0)} seconds ago`;
    } else if (diff < 3600) {
        const minutes = Math.floor(diff / 60).toFixed(0);
        return `${minutes} ${minutes === 1 ? "minute" : "minutes"} ago`;
    } else if (diff < 86400) {
        const hours = Math.floor(diff / 3600).toFixed(0);
        return `${hours} ${hours === 1 ? "hour" : "hours"} ago`;
    } else if (diff > 86400) {
        const days = Math.floor(diff / 86400).toFixed(0);
        return `${days} ${days === 1 ? "day" : "days"} ago`;
    } else {
        return `--`
    }
}
export const getTimes = (time) => {
    if (!time) return '--'
    let timestamp = +new Date(time);
    const now = +new Date();
    const diff = ((now - timestamp) / 1000);

    if (diff < 60) {
        if (diff < 1) {
            return `${Math.ceil(diff).toFixed(0)||1} seconds ago`
        }
        return `${diff.toFixed(0)} seconds ago`;
    } else if (diff < 3600) {
        const minutes = Math.floor(diff / 60).toFixed(0);
        return `${minutes} ${minutes === 1 ? "minute" : "minutes"} ago`;
    } else if (diff < 86400) {
        const hours = Math.floor(diff / 3600).toFixed(0);
        return `${hours} ${hours === 1 ? "hour" : "hours"} ago`;
    } else if (diff > 86400) {
        const days = Math.floor(diff / 86400).toFixed(0);
        return `${days} ${days === 1 ? "day" : "days"} ago`;
    } else {
        return `--`
    }
}
// 复制内容
export const copy = (text) => {
    const input = document.createElement('input');
    input.value = text; // 设置要复制的内容
    document.body.appendChild(input);
    input.select(); // 选中输入内容
    document.execCommand('copy'); // 执行复制操作
    document.body.removeChild(input); // 移除临时创建的input
    ElMessage.success("Copying and sharing the link succeeded");
    //     navigator.clipboard
    //         .writeText(text)
    //         .then(() => {
    //             // 复制成功的逻辑
    //             ElMessage.success("Copying and sharing the link succeeded");
    //         })
    //         .catch(error => {
    //             // 复制失败的逻辑
    //             ElMessage.error("Failed to copy the sharing link. Procedure");
    //         });
}

export function formatTimestamp(timestamp) {
    const date = new Date(timestamp);
    const options = {
        year: 'numeric',
        month: 'short',
        day: 'numeric'
    };
    const formattedDate = date.toLocaleDateString('en-US', options);
    return formattedDate;
}
// 年月日时分英文表达
export function formatTimestamps(timestamp) {
    const date = new Date(timestamp);
    const options = {
        year: 'numeric',
        month: 'short',
        day: 'numeric',
        hour: 'numeric',
        minute: 'numeric'
    };
    const formattedDate = date.toLocaleDateString('en-US', options);
    return formattedDate;
}
// 转换为时分
export function timeHous(timestamp) {
    // var timestamp = 1621011240000; // 时间戳

    var date = new Date(timestamp);
    var hours = date.getHours();
    var minutes = date.getMinutes();

    // 格式化时分
    var formattedTime = hours.toString().padStart(2, '0') + ':' + minutes.toString().padStart(2, '0');

    return formattedTime;
}



// <Join ref="join" />
// import Join from "@/components/join/index.vue";
// let join = ref("");
// @click.stop="joinIn(item)"

// /点击加入俱乐部
// const joinIn = item => {
//     console.log(item, "111111111111");
//     if (item.isJoin > 0) {
//         // 代表已经加入俱乐部
//     } else {
//         // 代表未加入俱乐部
//         join.value.obj = item;
//         join.value.money = item.subscription;
//         join.value.upLoadVisible = true;
//     }
// };